<%-- 
    Document   : orderComplete
    Created on : Mar 30, 2013, 11:42:38 PM
    Author     : Shaun McCready
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="org.domain.Customer" %>
<%@page import="org.domain.Item" %>
<%@page import="org.domain.ItemShippingStatusList" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.List"%>
<%@page import="org.helper.ShipGoods" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%
    //get the response from the item list and make sure it is not null
    ItemShippingStatusList issl = (ItemShippingStatusList) request.getAttribute("result");
        
    //get customer info
    Customer c = issl.getCust();
    if(c == null) {
        System.out.println("huh?");
    }
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Order Completed</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
  <script type="text/javascript" src=
  "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
  <script type="text/javascript">
//<![CDATA[
  function getParameterByName(name)
  {
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
  }
  var itemname = getParameterByName('itemname');
  $(document).ready(function(){
        $('#nav li').hover(function () {
                $(this).find('.dropDown').slideToggle(200);
                $(this).toggleClass('active');
  });

                   $('#itemC').val(itemname);

        });

  //]]>
  </script>
</head>

<body>
  <div class="wrapper">
    <div id="navContainer">
      <ul class="clear" id="nav">
        <li class="first"><a class="active" href="home.jsp">Home</a></li>

        <li>
          <a href="camera.jsp">Products</a>

          <div class="dropDown">
            <div class="top"></div>

            <div class="items">
              <ul>
                <li class="first"><a href="camera.jsp">Cameras</a></li>

                <li><a href="dvd.jsp">DVD Players</a></li>

                <li class="last"><a href="tv.jsp">Televisions</a></li>
              </ul>
            </div>
          </div>
        </li>

        <li><a href="order.jsp">Order</a></li>

        <li><a href="payment.jsp">Payment</a></li>

        <li class="last"><a href="logout">Logout</a></li>
      </ul>
    </div>
  </div>

  <div id="mainContent">
        <h2>Your Order is now Completed!</h2>
        
        <div id="orderSummary">
            <br/>
            <hr/>
            <br/>
            <div id="customerInfo">
                <h2>Shiped To:</h2>

                <ul style="list-style:none; margin-left:-15px;">
                    <li><%=c.getName()%></li>
                    <li><%=c.getAddress1()%></li>
                    <li><%=c.getAddress2()%></li>
                    <li><%=c.getCity()%> , <%=c.getProvince()%> </li>
                    <li><%=c.getCountry()%> , <%=c.getPostalCode()%></li>
                </ul>

            </div>
            <br/>
            <hr/>
            <br/>
            <div id="order">


                <h2>Shipped Items:</h2>
                <table border="0"  style="border-spacing: 8px; margin-left:15px;">
                    <tr>
                        <th>Product</th>
                        <th>Manufacturer</th>
                        <th>Quantity</th>
                        <th>Unit Price</th>
                        <th>Item Total </th>
                    </tr>



                <%
                double totalCost = 0;
                    if(!issl.getShippedItems().isEmpty()) {
                        ArrayList<Item> shipped = issl.getShippedItems();

                       // List<Item> listofstuff = issl.getShippedItems();

                       

                        for(int i = 0; i < shipped.size(); i++) {
                            double cost = shipped.get(i).getQuantity() * shipped.get(i).getPrice();
                            totalCost += cost;

                            out.print("<tr>" + 
                                          "<td> " + shipped.get(i).getProduct() + "</td>"+
                                          "<td> " + shipped.get(i).getManufacturer() + "</td>" +
                                          "<td> " + shipped.get(i).getQuantity() + "</td>" +
                                          "<td> " + shipped.get(i).getPrice() + "</td>" +
                                          "<td> $" + cost + "</td>" +
                                      "</tr>");
                        }
                     
                    }
                %>

                </table>
                <%
                 out.print("<p style='margin-left:-25px;'>The total cost of your order is $" + totalCost + "</p>");
                 %>

            </div>
            <br />
            <div id ="notShipped">
            <%

            if(!issl.getNotShippedItems().isEmpty()) {

            %>


            <br/>
            <hr/>
            <br/>
            <h2>Not Shipped Items:</h2>
                 <table border="0" style="border-spacing: 8px; margin-left:15px;">
                    <tr>
                        <th>Product</th>
                        <th>Manufacturer</th>
                        <th>Quantity</th>
                    </tr>

                <%
                    
                        ArrayList<Item> notShipped = issl.getNotShippedItems();
                        for(int i = 0; i < notShipped.size(); i++) {
                            out.print("<tr>" + 
                                          "<td>" + notShipped.get(i).getProduct() + "</td>"+
                                          "<td>" + notShipped.get(i).getManufacturer() + "</td>" + 
                                          "<td>" + notShipped.get(i).getQuantity() + "</td>" +                                          
                                      "</tr>");
                        }
                    }
                %>




 </table>
            </div>
        </div>
        <br /><br />
        <p style="margin-left:-25px;">Thank you for choosing Company X for your electronic goods. We hope you come again!</p>
  </div>
          <div id="footer">
    <center>
 <a href="home.jsp">Home</a> | <a href="camera.jsp">Products</a> | <a href="order.jsp">Order</a> | <a href=
      "payment.jsp">Payment</a> | <a href="logout">Logout</a><br />
      Copyright 2013 by Company X. All Rights Reserved.
    </center>
  </div>
    </body>
</html>
